package com.ruoyi.project.his.system.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.his.system.domain.HisDepartment;
import com.ruoyi.project.his.system.service.IHisDepartmentService;
import com.ruoyi.project.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/his/department")
public class HisDepartmentController extends BaseController {
    //声明业务层属性
    @Autowired
    private IHisDepartmentService iHisDepartmentService;
    /**
     * 获取岗位列表
     */
   // @PreAuthorize("@ss.hasPermi('system:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisDepartment hisDepartment)
    {
        startPage();
        List<HisDepartment> hisDepartments = iHisDepartmentService.selectHisDepartmentList(hisDepartment);
        return getDataTable(hisDepartments);
    }
    /**
     * 新增科室信息
     * @RequestBody 表明请求数据就是请求体 请求数据就是一个大json、
     *
     */
    //@PreAuthorize("@ss.hasPermi('system:post:add')")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping("/addDepartment")
    public AjaxResult add(@RequestBody HisDepartment hisDepartment) {

        hisDepartment.setCreateBy(SecurityUtils.getUsername());
        hisDepartment.setDepartmentNum("0");
        return toAjax(iHisDepartmentService.insertHisDepartment(hisDepartment));
    }
    /**
     * 根据科室编号获取详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:post:query')")
    @GetMapping(value = "/{departmentId}")
    public AjaxResult getInfo(@PathVariable Long departmentId)
    {
        return AjaxResult.success(iHisDepartmentService.selectDepartmentById(departmentId));
    }
    /**
     * 修改科室
     */
   // @PreAuthorize("@ss.hasPermi('system:post:edit')")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit( @RequestBody HisDepartment hisDepartment)
    {
        hisDepartment.setUpdateBy(SecurityUtils.getUsername());//给接请求数据实体类赋默认值，谁改的的是谁
        return toAjax(iHisDepartmentService.updateDepartment(hisDepartment));
    }

    /**
     * 删除科室
     */
   // @PreAuthorize("@ss.hasPermi('system:post:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{departmentIds}")
    public AjaxResult remove(@PathVariable Long[] departmentIds)
    {
        return toAjax(iHisDepartmentService.deleteDepartmentByIds(departmentIds));
    }

}
